package com.explorex.infra.puma.gateway.application;


import com.explorex.infra.puma.gateway.netty.ext.MessageEmitter;
import com.explorex.infra.puma.gateway.netty.ws.DefaultWebSocketEvent;
import com.explorex.infra.puma.gateway.netty.ws.WebSocketServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(scanBasePackages = {"com.explorex"})
public class PumaApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext applicationContext = SpringApplication.run(PumaApplication.class, args);
        startUpWsServer(applicationContext);
    }

    private static void startUpWsServer(ApplicationContext context) {
        WebSocketServer server = new WebSocketServer();
        server.setCheckHeartbeat(true);
        server.setWebSocketPath("/longlink");
        server.setWebSocketEvent(new DefaultWebSocketEvent());
        server.setContext(context);
        server.bind(5444);
        MessageEmitter.setBaseServer(server);
    }
}
